#include "StatusGrpcClient.h"
#include "ConfigMgr.h"

GetChatServerRsp StatusGrpcClient::GetChatServer(int uid){
	ClientContext context;
	GetChatServerReq req;
	GetChatServerRsp rsp;
	req.set_uid(uid);

	auto stub = _stubPool->GetStub();
	Status status = stub->GetChatServer(&context, req, &rsp);
	_stubPool->returnConnection(std::move(stub));
	if (!status.ok()){
		rsp.set_error(ErrorCodes::RPCFailed);
	}
	return rsp;
}

StatusGrpcClient::StatusGrpcClient()
	: _stubPool(std::make_unique<StatusStubPool>(5, ConfigMgr::GetInstance()["StatusServer"]["Host"]
		, ConfigMgr::GetInstance()["StatusServer"]["Port"]))
{ }
